package com.jin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jin.bean.TruckRecord;
import com.jin.dao.TruckRecordMapper;
import com.jin.service.TruckRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Created on 2025/2/24.
 * @author Zhongyuan Jin
 */
@Service
public class TruckRecordServiceImpl
        extends ServiceImpl<TruckRecordMapper, TruckRecord>
        implements TruckRecordService {

    @Autowired
    private TruckRecordMapper truckRecordMapper;

    @Override
    public Page<TruckRecord> getTruckRecordsByConditions(
            String gateName,
            String plate,
            String unitName,
            Date startTime,
            Date endTime,
            int pageNum,
            int pageSize) {

        Page<TruckRecord> pageParam = new Page<>(pageNum, pageSize);  // 创建分页参数
        return truckRecordMapper.getTruckRecordsByConditions(pageParam, gateName, plate, unitName, startTime, endTime);
    }

    @Override
    public Page<TruckRecord> getTruckRecordsByUnitId(Integer unitId, int pageNum, int pageSize) {
        Page<TruckRecord> pageParam = new Page<>(pageNum, pageSize);
        QueryWrapper<TruckRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("unit_id", unitId);
        return truckRecordMapper.selectPage(pageParam, queryWrapper);
    }



    // TruckRecordServiceImpl.java
    @Override
    public List<TruckRecord> getTruckRecordsByConditionsForExport(String gateName, String plate, String unitName, Date startTime, Date endTime) {
        return truckRecordMapper.selectTruckRecordsByConditionsForExport(gateName, plate, unitName, startTime, endTime);
    }

}
